package config;

import com.controller.AuthenticationInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
@ComponentScan("com")
public class AppConfig implements WebMvcConfigurer {

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/WEB-INF/", ".jsp");
    }

    /*@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
                .addResourceHandler("/static/**")
                .addResourceLocations("classpath:/public/");
    }
*/

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 顺序：值越小优先级越高
//        registry.addInterceptor(new FirstInterceptor()).order(50);
//        registry.addInterceptor(new SecondInterceptor()).order(100);
        registry
                .addInterceptor(new AuthenticationInterceptor())
                .order(Ordered.HIGHEST_PRECEDENCE)
                .excludePathPatterns("/login")
                .excludePathPatterns("/static/**");
    }
}
